#generate "type" based on the values of varnum
countries_10 <- countries_10 %>% mutate(types= case_when(varnum==1 ~ "Fruits",
varnum==2 ~ "Non-starchy vegetables",
varnum==3 ~ "Potatoes",
varnum==4 ~ "Other starchy vegetables",
varnum==5 ~ "Beans and legumes",
varnum==6 ~ "Nuts and seeds",
varnum==7 ~ "Refined grains",
varnum==8 ~ "Whole grains",
varnum==9 ~ "Total processed meats",
varnum==11 ~ "Total seafoods",
varnum==12 ~ "Eggs",
varnum==13 ~ "Cheese",
varnum==14 ~ "Yoghurt",
TRUE ~ "Unprocessed red meats"))
#generate "country" based on the values of iso3
countries_10 <- countries_10 %>% mutate(country= case_when(iso3=="CHN" ~ "China",
iso3=="DEU" ~ "Germany",
iso3=="JPN" ~ "Japan",
iso3=="PRK" ~ "North Korea",
iso3=="PAK" ~ "Pakistan",
iso3=="PSE" ~ "Palestine",
iso3=="SDE" ~ "Sudan",
iso3=="SYR" ~ "Syria",
iso3=="USA" ~ "United States",
iso3=="IND" ~ "India"))
#select the general data points (all demographics features = 999)
gen_countries <- countries_10 %>% filter(age == 999 &
female == 999,
urban == 999,
edu == 999)
d_stru_18 <- gen_countries %>% filter(year==2018) %>%
group_by(country) %>%
summarise(types, total = sum(median), percentage=(round(median/total,4))*100) %>%
ggplot(aes(fill=types, y=percentage, x=country)) +
geom_bar(position="stack", stat="identity") +
labs(x="Country", title="Dietary Sturcture in 2018") +
coord_flip()
ggplotly(d_stru_18) %>% layout(xaxis = list(title = "Percentage in Diet"),
legend = list(orientation = "h",itemsizing="constant"))
d_stru_90 <- gen_countries %>% filter(year==1990) %>%
group_by(country) %>%
summarise(types, total = sum(median), percentage=(round(median/total,4))*100) %>%
ggplot(aes(fill=types, y=percentage, x=country)) +
geom_bar(position="stack", stat="identity") +
labs(x="Country", title="Dietary Sturcture in 1990") +
coord_flip()
ggplotly(d_stru_90) %>% layout(xaxis = list(title = "Percentage in Diet"),
legend = list(orientation = "h",itemsizing="constant"))
After comparing the dietary structure in 2018 and in 1990, we find that Chinese experienced the most significant changes, therefore, we pay attention to the dietary structure based on demographic characteristics in China. Among all the types of food, two of them experienced significant changes– Refined grains and Non-starchy vegetables. Therefore, we mainly focus in the changes of these two types of food in China.
gender <- countries_10 %>%
filter(age == 999 & urban == 999 & edu == 999 & country == "China" &
female != 999 & year != 2020) %>%
mutate(gender= case_when(female==1 ~ "Female",
female==0 ~ "Male"))
gender_China <- gender %>%
group_by(year) %>%
summarise(types, gender, total = sum(median), percentage=(round(median/total,4))*100)
rg_gender <- gender_China %>%
filter(types == "Refined grains") %>%
ggplot(aes(x = year, y=percentage,group=gender,color=gender)) +
geom_line( size=1) +
geom_point(size=1) +
labs(x="Year", y="Percentage of Refined Grains", title="Refined Grains in Dietary Structure by Gender in China") +
theme_classic()
ggplotly(rg_gender)
nv_gender <- gender_China %>%
filter(types == "Non-starchy vegetables") %>%
ggplot(aes(x = year, y=percentage,group=gender,color=gender)) +
geom_line( size=1) +
geom_point(size=1) +
labs(x="Year", y="Percentage of Non-starchy vegetables", title="Non-starchy vegetables in Dietary Structure by Gender in China") +
theme_classic()
ggplotly(nv_gender)
area <- countries_10 %>% filter(age == 999 & urban != 999 &
edu == 999 & country == "China" &
female == 999 & year != 2020) %>%
mutate(area= case_when(urban==1 ~ "Urban",
urban==0 ~ "Rural"))
area_China <- area %>%
group_by(year) %>%
summarise(types, area, total = sum(median), percentage=(round(median/total,4))*100, .groups = 'drop')
library(grid)
ru.mid<-ggplot(area_China,aes(x=1,y=types))+geom_text(aes(label=types))+
geom_segment(aes(x=0.94,xend=0.96,yend=types))+
geom_segment(aes(x=1.04,xend=1.065,yend=types))+
ggtitle("")+
ylab(NULL)+
scale_x_continuous(expand=c(0,0),limits=c(0.94,1.065))+
theme(axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.background=element_blank(),
axis.text.x=element_text(color=NA),
axis.ticks.x=element_line(color=NA),
plot.margin = unit(c(1,-1,1,-1), "mm"))
ru_90 <- area_China %>%
filter(area=="Rural" & year==1990) %>%
ggplot(aes(x = types, y = percentage,fill = types)) +
geom_bar(stat = "identity") + ggtitle("Dietary Structure(Rural China,1990)") +
geom_text(aes(y=10, label = percentage),color = "black") +
coord_flip() + scale_y_reverse() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position="none",
panel.background=element_blank(),
plot.title = element_text(size = 10),
plot.margin = unit(c(1,-1,1,0), "mm"))
ru_18 <- area_China %>%
filter(area=="Rural" & year==2018) %>%
ggplot(aes(x = types, y = percentage, fill = types)) +
geom_bar(stat = "identity") + ggtitle("Dietary Structure(Rural China,2018)") +
geom_text(aes(y=10, label = percentage),color = "black") +
coord_flip() + xlab(NULL) +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position="none",
panel.background=element_blank(),
plot.title = element_text(size = 10),
plot.margin = unit(c(1,-1,1,0), "mm"))
library(gridExtra)
ru1 <- ggplot_gtable(ggplot_build(ru_90))
ru2 <- ggplot_gtable(ggplot_build(ru_18))
ru.mid <- ggplot_gtable(ggplot_build(ru.mid))
grid.arrange(ru1,ru.mid,ru2,ncol=3,widths=c(3/9,3/9,3/9))
ur_90 <- area_China %>%
filter(area=="Urban" & year==1990) %>%
ggplot(aes(x = types, y = percentage,fill = types)) +
geom_bar(stat = "identity") + ggtitle("Dietary Structure(Urban China,1990)") +
geom_text(aes(y=10, label = percentage),color = "black") +
coord_flip() + scale_y_reverse() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position="none",
panel.background=element_blank(),
plot.title = element_text(size = 10),
plot.margin = unit(c(1,-1,1,0), "mm"))
ur_18 <- area_China %>%
filter(area=="Urban" & year==2018) %>%
ggplot(aes(x = types, y = percentage, fill = types)) +
geom_bar(stat = "identity") + ggtitle("Dietary Structure(Urban China,2018)") +
geom_text(aes(y=10, label = percentage),color = "black") +
coord_flip() + xlab(NULL) +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position="none",
panel.background=element_blank(),
plot.title = element_text(size = 10),
plot.margin = unit(c(1,-1,1,0), "mm"))
library(gridExtra)
ur1 <- ggplot_gtable(ggplot_build(ur_90))
ur2 <- ggplot_gtable(ggplot_build(ur_18))
grid.arrange(ur1,ru.mid,ur2,ncol=3,widths=c(3/9,3/9,3/9))